import jieba
import wordcloud
from imageio.v3 import imread
txt = open("text/三中全会.txt", "r", encoding="utf-8").read()
words = jieba.lcut(txt)
counts = {}
for word in words:
    if len(word) == 1:
        continue
    else:
        counts[word] = counts.get(word,0)+1
ls = " ".join(words)
items = list(counts.items())
items.sort(key=lambda x:x[1], reverse=True)
for i in range(15):
    word, count = items[i]
    print("{0:<10}{1:>5}".format(word,count))

wordscloud = wordcloud.WordCloud(stopwords={"的","和"}, max_font_size=100, min_font_size=15, max_words=150, font_path="font/SongTi.ttf", width=1000, height=700, background_color="white", mask=imread(
    "mark/photo2.png"))
wordscloud.generate(ls)
wordscloud.to_file("cloud_to_red.png")